function uuid() {
  return "xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx".replace(/[xy]/g, function (c) {
    var r = (Math.random() * 16) | 0,
      v = c == "x" ? r : (r & 0x3) | 0x8;
    return v.toString(16);
  });
}
import drawQrcode from "./weapp.qrcode.esm.js";
import utils from "./utils";

Component({
  mixins: [],
  data: {
    id: "",
  },
  props: {
    text: "",
    width: 0,
    height: 0,
  },
  didMount() {
    this.setData({
      id: uuid(),
    });

    this.props.refctx && this.props.refctx(this);

    this.initCanvas();
  },
  didUpdate() {},
  didUnmount() {},
  methods: {
    initCanvas() {
      // eslint-disable-next-line no-undef
      let qrCodeCtx = (this.qrCodeCtx = my.createCanvasContext(this.data.id));
      let width = this.props.width;

      let text = this.props.text;

      drawQrcode({
        width: width,
        height: width,
        ctx: qrCodeCtx,
        text: text,
        image: {
          dx: 0,
          dy: 0,
          dWidth: 0,
          dHeight: 0,
        },
      });
    },
  },
});
